#车辆里程

import pandas as pd

import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

df=pd.read_csv("二手车基本信息.csv")
df['里程(万公里)'].replace("百公里内","100.0",inplace=True)
mileage_data=df['里程(万公里)'].astype('float')
def mileage(x):
    if x<=1.0:
        return "一万公里以内"
    elif 1.0<x<=3.0:
        return "1-3万公里"
    elif 3.0 < x <= 5.0:
        return "3-5万公里"
    elif 5.0 < x <= 8.0:
        return "5-8万公里"
    elif 8.0 < x <= 10.0:
        return "8-10万公里"
    else:
        return "10万以上"
df["公里分级"]=mileage_data.apply(lambda x:mileage(x))
mileage_num=df["公里分级"].value_counts().tolist()
mileage_list=df["公里分级"].value_counts().index.tolist()


c = (
    Line()
    .add_xaxis(mileage_list)
    .add_yaxis("里程", mileage_num)
    .set_global_opts(title_opts=opts.TitleOpts(title="车辆里程"))
    .render("bigdata/cardata/车辆里程.html")
)

